﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Model;
using DevExpress.Xpo;
using POS.Framework;
using BLL;

namespace POS.UserControl.Dialog
{
    public partial class frmPopProvider : DevExpress.XtraEditors.XtraForm
    {
        public frmPopProvider()
        {
            InitializeComponent();
        }

        internal B_Provider GetSelectRow()
        {
            if (this.gridView.SelectedRowsCount <= 0) return null;

            B_Provider selectRow = this.gridView.GetFocusedRow() as B_Provider;

            return selectRow;
        }

        private void frmPopProvider_Load(object sender, EventArgs e)
        {
            this.gridView.CustomDrawRowIndicator += new DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventHandler(SpecialGridView.DrawRowIndicator);
            SetButtonClickEvent();
            SearchData();
        }
        void SetButtonClickEvent()
        {
            this.popFormButtonUC.OK.Click += new EventHandler(btnOK_Click);
            this.gridView.DoubleClick += new EventHandler(btnOK_Click);
            this.gridView.KeyPress += new KeyPressEventHandler(btnOK_Click);
        }

        void btnOK_Click(object sender, EventArgs e)
        {
            if (GetSelectRow() != null)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
        }

        void SearchData()
        {
            XPCollection<B_Provider> provider = new XPCollection<B_Provider>(DatabaseSchema.Session);
            this.grid.DataSource = provider;
            SpecialGridView.SetGridViewIndicatorWidth(provider.Count, this.gridView);
        }
    }
}